#include "std_class.hpp"
#include "../../nonos/mcus/esp8266/stdinc.h"


u16 ByteBuffer::age() {
	return osElapsedMs(_timestamp);
}

bool ByteBuffer::put(char ch) {
	if(_dlen >= _size-1) { return false; }
	_data[_dlen] = ch; _dlen++;
	_timestamp = osGetMs();
	return true;
}

bool ByteBuffer::put(u16 len, const u8* data) {
	if(_dlen+len > _size-1) { return false; }
	memcpy(_data+_dlen, data, len); _dlen += len;
	_timestamp = osGetMs();
	return true;
}

void ByteBuffer::lshift(u16 nbytes) {
	if(!_dlen || !nbytes) { return; }

	if(_dlen > nbytes) {
		_dlen -= nbytes;
		memcpy(_data, _data+nbytes, _dlen);
	} else {
		_dlen = 0;
	}
}
